package com.example.weather_news.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * Created by 逝 on 2017/06/09.
 */

public class ShareUtils {
    private final static String Table="Weather";
    public final static String isFirstIn="isFirstIn";
    public final static String USER_NAME="name";
    public final static String FLASH="Flash";
    public final static String INDEX="index";
    public final static String IMAGE_PATH="imagePath";

    public static void setString(Context context, String key, String data){
        SharedPreferences sp=context.getSharedPreferences(ShareUtils.Table, Context.MODE_PRIVATE);
        Editor editor=sp.edit();
        editor.putString(key,data);
        editor.apply();
    }

    public static String getString(Context context, String key, String data){
        SharedPreferences sp=context.getSharedPreferences(ShareUtils.Table, Context.MODE_PRIVATE);
        return sp.getString(key,data);
    }

    public static void setInt(Context context, String key, int data){
        SharedPreferences sp=context.getSharedPreferences(ShareUtils.Table, Context.MODE_PRIVATE);
        Editor editor=sp.edit();
        editor.putInt(key,data);
        editor.apply();
    }

    public static int getInt(Context context, String key){
        SharedPreferences sp=context.getSharedPreferences(ShareUtils.Table, Context.MODE_PRIVATE);
        return sp.getInt(key,0);
    }

    public static void setBoolean(Context context, String key, boolean data){
        SharedPreferences sp=context.getSharedPreferences(ShareUtils.Table, Context.MODE_PRIVATE);
        Editor editor=sp.edit();
        editor.putBoolean(key,data);
        editor.apply();
    }

    public static boolean getBoolean(Context context, String key, boolean data){
        SharedPreferences sp=context.getSharedPreferences(ShareUtils.Table, Context.MODE_PRIVATE);
        return sp.getBoolean(key,data);
    }
}
